﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

    public class PHIEUXUAT_DATAACCESS
    {
        private static string sp_Name = "SP_PHHIEUXUAT";
        public static void ExcuteQueryString(string ACTION, PHIEUXUAT_ENTITY PXentity)
        {
            SqlCommand com = new SqlCommand();
            DATABASE_CONTROL csdl = new DATABASE_CONTROL();
            try
            {

                com.Connection = csdl.CheckConnect();
                com.Parameters.AddWithValue("@ACTION", ACTION);
                if (PXentity != null)
                {
                    com.Parameters.AddWithValue("@MAPX", PXentity.MAPX);
                    com.Parameters.AddWithValue("@SOPX", PXentity.SOPX);
                    com.Parameters.AddWithValue("@MADH", PXentity.MADH);
                    com.Parameters.AddWithValue("@NGAYXUAT", PXentity.NGAYXUAT);

                    //com.Parameters.AddWithValue("@MAHD", PX.MAHD);
                    //com.Parameters.AddWithValue("@MAKH", dh.MAKH);
                    //com.Parameters.AddWithValue("@NGAYHD", dh.NGAYHD);
                    //com.Parameters.AddWithValue("@VAT", dh.VAT);
                    //com.Parameters.AddWithValue("@THANHTIEN", dh.THANHTIEN);
                }
                com.CommandType = CommandType.StoredProcedure;
                com.CommandText = sp_Name;
                if (com.Connection.State == ConnectionState.Closed)
                {
                    com.Connection.Open();
                }
                com.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                com.Connection.Close();
            }
        }
        public static DataSet GETDATATABLE(string ACTION, PHIEUXUAT_ENTITY PXentity)
        {
            SqlCommand com = new SqlCommand();
            DATABASE_CONTROL csdl = new DATABASE_CONTROL();
            DataSet ds;
            try
            {

                com.Connection = csdl.CheckConnect();
                com.Parameters.AddWithValue("@ACTION", ACTION);
                if (PXentity != null)
                {
                    com.Parameters.AddWithValue("@MAPX", PXentity.MAPX);
                    com.Parameters.AddWithValue("@SOPX", PXentity.SOPX);
                    com.Parameters.AddWithValue("@MADH", PXentity.MADH);
                    com.Parameters.AddWithValue("@NGAYXUAT", PXentity.NGAYXUAT);

                }
                com.CommandType = CommandType.StoredProcedure;
                com.CommandText = sp_Name;
                if (com.Connection.State == ConnectionState.Closed)
                {
                    com.Connection.Open();
                }
                ds = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter(com);
                da.Fill(ds);
                return ds;
            }
            catch (Exception ex)
            {
                return new DataSet();
                throw ex;
            }
            finally
            {
                com.Connection.Close();
            }
        }
    
        public static int MAXID(string ACTION, PHIEUXUAT_ENTITY PX)
        {
            SqlCommand com = new SqlCommand();
            DATABASE_CONTROL csdl = new DATABASE_CONTROL();
            DataSet ds;
            try
            {

                com.Connection = csdl.CheckConnect();
                com.Parameters.AddWithValue("@ACTION", ACTION);
                if (PX != null)
                {
                    com.Parameters.AddWithValue("MAPX", PX.MAPX);
                    com.Parameters.AddWithValue("SOPX", PX.SOPX);                  
                    com.Parameters.AddWithValue("MADH", PX.MADH);
                    com.Parameters.AddWithValue("NGAYXUAT", PX.NGAYXUAT);
                  
                }
                com.CommandType = CommandType.StoredProcedure;
                com.CommandText = sp_Name;
                if (com.Connection.State == ConnectionState.Closed)
                {
                    com.Connection.Open();
                }
                return (int)com.ExecuteScalar();
            }
            catch (Exception ex)
            {
                return 1;
                throw ex;
            }
            finally
            {
                com.Connection.Close();
            }
        }
    
    }
